package edu.java.homework.hw09.exercises.nikolay.food.product;

import edu.java.homework.hw09.exercises.nikolay.food.Priceable;
import edu.java.homework.hw09.exercises.nikolay.food.ingredient.type.IngredientType;

public abstract class Product implements Priceable {

	private int quantity;

	// --- Constructors --------------------------------------------------------

	public Product(int quantity) {
		this.quantity = quantity;
	}

	// --- Getters and Setters -------------------------------------------------

	public void setQuantity(int quantity) {
		this.quantity = quantity;
	}

	public int getQuantity() {
		return quantity;
	}

	// we delegate to the inheritors to redefine this method
	public abstract IngredientType getType();

	// --- Methods (Priceable) -------------------------------------------------

	@Override
	public int getPrice() {
		IngredientType type = getType();
		if (type == null) {
			throw new IllegalStateException("The ingredient type is null.");
		}
		return type.getPrice() * getQuantity();
	}

	// --- Methods (Object) ----------------------------------------------------

	@Override
	public String toString() {
		return getType().toString();
	}
}
